/**
 * zmn系统模块-系统编辑
 * 文件命名格式：zmn.模块.表/功能.js
 * @author heguanghua
 * @since 2020/04/16 10:11
 */
layui.define(['form', 'layedit', 'zmnApp', 'laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    let zmnApp = layui.zmnApp;

    form.render(null, "zmn-form");

    // 提交
    form.on('submit(zmn-form-submit)', function(obj){
        var data = obj.field;
        var url = zmnApp.SYS_BASE_URL +"/sys/modify/addEdit.action";
        var jumpStop = false;
        $.ajax({
            async: false,
            type: "POST", url: url,
            contentType: "application/json", dataType: "json", data: JSON.stringify(data),
            success:function(json) {
                var message = json.status == zmnStatus.SUCCESS ? "操作成功！" : json.message;
                layer.msg(message);
                if(json.status == zmnStatus.SUCCESS && !zmnUtil.isNotZeroInteger(data.sysId)) {
                    zmnPage.direct(zmnApp.SYS_BASE_URL +"/sys/detail.action?sysId=" + json.data, 0);
                } else if(json.status == zmnStatus.FAIL) {
                    jumpStop = true;
                }
                return;
            },
            error:function(XMLHttpRequest, tsysStatus, errorThrown){}
        })
        if(jumpStop || data.sysId * 1 > 0) {
            return false;
        }
    });

    form.verify({
        isRe: function (value) {
            let pattern = /^1[23456789]\d{9}$/;
            if (zmnApp.notNull(value)) {
                if (!pattern.test(value)) {
                    return "请输入正确手机号!";
                }
            }
        },
        isEmail: function (val) {
            let reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
            if (!reg.test(val)) {
                return "请输入正确邮箱!";
            }
        },
        isLetter: function (val) {
            let reg = /^[a-zA-Z]+$/;
            if (!reg.test(val)) {
                return "请输入姓名拼音!";
            }
        }
    });
    
    //对外暴露的接口
    exports('sys_detail', {});
});